package com.yl.nettylearning.netty.day04;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.util.CharsetUtil;


/**
 * @author yangl
 */
public class ByteBuf02 {
    public static void main(String[] args) {
        ByteBuf byteBuf = Unpooled.copiedBuffer("hello, world", CharsetUtil.UTF_8);
        if(byteBuf.hasArray()){
            byte[] content = byteBuf.array();
            System.out.println(new String(content, CharsetUtil.UTF_8));
            System.out.println("byteBuf:" + byteBuf);
            System.out.println(byteBuf.arrayOffset());
            System.out.println(byteBuf.readerIndex());
            System.out.println(byteBuf.writerIndex());
            System.out.println(byteBuf.readByte()); //如果用的是readByte，因为已经读取了一个了，字后输出的可读的字节是11
            System.out.println(byteBuf.getByte(0));//如果用的是getByte，最后可读的字节还是12
            System.out.println(byteBuf.readableBytes());
        }
    }
}
